package controller

import (
	"path"
	"smc-admin/response"
	"strconv"
	"time"

	"github.com/gin-gonic/gin"
)

// @Tags         文件上传
// @Accept 		 mpfd
// @Param        file  formData  file  true  "上传文件"
// @Success      200   {object}  response.Body
// @Router       /upload [post]
func SingleFileUpload(ctx *gin.Context) {
	file, err := ctx.FormFile("file")
	if err != nil {
		panic(err.Error())
	}
	timeStr := time.Now().Unix()
	num := strconv.FormatInt(timeStr, 10)
	filePath := path.Join("./upload", num+file.Filename)

	e := ctx.SaveUploadedFile(file, filePath)
	if e != nil {
		panic(e.Error())
	}
	response.Success(ctx, response.Body{
		Data: filePath,
		Msg:  "上传成功",
	})
}
